package com.yixun.qfbao;


import com.yixun.qfbao.api.service.CPReportService;
import com.yixun.qfbao.apidto.UpdateSaleStatusReqDto;
import com.yixun.qfbao.apidto.UpdateSaleStatusResDto;

import com.yixun.qfbao.model.enums.SystemIdEnum;
import com.yixun.qfbao.util.WxAccessTokenCacheUtils;

import com.yixun.qfbao.vo.UpdateSaleStatusReqVo;
import com.yixun.qfbao.xf.model.dto.CustomerPremisesDto;
import com.yixun.qfbao.xf.service.CustomerPremisesService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;

/**
 *  RunWith Bean实例化容器
 *  SpringBootTest 配置文件读取
 *  WebAppConfiguration 加载Web配置（因为使用的外部Tomcat启动）
 *
 *
 * @Author: wm
 * @Date: 2021-02-23  14:59
 * @Version 1.0
 */

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
@WebAppConfiguration
public class OpenApiController {

    @Autowired
    private CPReportService cpReportService;
    @Autowired
    private CustomerPremisesService customerPremisesService;
    @Autowired
    private WxAccessTokenCacheUtils wxAccessTokenCacheUtils;

    //测试案例
    @Test
    public void fun(){
        log.info("输出。。。");
        UpdateSaleStatusReqVo reqVo = new UpdateSaleStatusReqVo();
        UpdateSaleStatusReqDto reqDto = new UpdateSaleStatusReqDto();
        reqDto.setRecommendedChannelId("5177606");
        reqDto.setTransStatus("2");
        reqVo.setParams(reqDto);
        // 通过报备ID获取公司信息
        CustomerPremisesDto cp = customerPremisesService.selectCompanyByCpId(Long.valueOf(reqDto.getRecommendedChannelId()));
        //获取分销助手和案场助手的微信accessToken
        String agencyAccessToken = wxAccessTokenCacheUtils.getAccessToken(cp.getCompanyUuid(), SystemIdEnum.AGENCY_h5.getCode(), null);
        String assistantAccessToken = wxAccessTokenCacheUtils.getAccessToken(cp.getCompanyUuid(), SystemIdEnum.ASSISTANT.getCode(), null);
        UpdateSaleStatusResDto updateSaleStatusResDto = cpReportService.newUpdateSaleStatusHander(reqDto, cp, agencyAccessToken, assistantAccessToken);
        log.info("================返回结果集===============");
        log.info(updateSaleStatusResDto.getResultMsg());

    }
}
